<template>
	
	<view class="container">
		<view class="text-area">
			<!-- <text class="title">{{title}}</text> -->
		</view>
		<view class="text-nitice">
			<text class="nitice">{{notice}}</text>
		</view>
		<uni-section title="尊敬的用户,填写注册信息" type="line">
			<view class="example">
				<!-- 基础用法，不包含校验规则 -->
				<uni-forms >
					<uni-forms-item label="手机号" required>
						<uni-easyinput   v-model="userName"  format="number" maxLength="11" placeholder="手机号" />
					</uni-forms-item>
					<uni-forms-item label="密码" required>
						<uni-easyinput type="password" v-model="pwd" placeholder="请输入密码" />
					</uni-forms-item>
			<uni-forms-item label="确认密码" required>
				<uni-easyinput v-model="rePwd" type="password" placeholder="请再次输入密码" />
			</uni-forms-item>
				</uni-forms>
				
			</view>
		</uni-section>
	
			<button type="primary"  @click="register()">注册</button>
			<button type="default" @click="login()">返回</button>
				

	
		
	</view>
	<!-- <view class="content nvue-page-root">
		<form >
			<view class="text-area">
				<text class="title">{{title}}</text>
			</view>
			<view class="text-nitice">
				<text class="nitice">{{notice}}</text>
			</view>
			<view class="uni-common-mt">
				<view class="uni-form-item uni-column">
					<view class="title"></view>
					<view class="uni-input-wrapper">
						<input class="uni-input" v-model="userName" type="number" focus maxlength="11" placeholder="手机号" />
					</view>
				</view>
		
		
				<view class="uni-form-item uni-column">
					<view class="title"></view>
					<view class="uni-input-wrapper">
						<input class="uni-input" v-model="pwd" placeholder="请输入密码" :password="showPassword" />
						<text class="uni-icon" :class="[!showPassword ? 'uni-eye-active' : '']" @click="changePassword">&#xe568;</text>
					</view>
				</view>
				<view class="uni-form-item uni-column">
					<view class="title"></view>
					<view class="uni-input-wrapper">
						<input class="uni-input" v-model="rePwd" placeholder="请再次输入密码" :password="showRePassword" />
					<text class="uni-icon" :class="[!showRePassword ? 'uni-eye-active' : '']" @click="changeRePassword">&#xe568;</text>
					</view>
				</view>
				<view class="uni-form-item uni-column">
					
					
						<button type="primary"  @click="register()">注册</button>
						<button type="default" @click="login()">返回</button>

					
				</view>


			</view>
		</form>
	</view> -->
</template>

<script>
	import constant from '@/store/constant.js'
	const baseUrl=constant.baseUrl;
	export default {
		data() {
			return {
				title: '尊敬的用户,请注册',
				notice:'',
				showPassword: true,
				showRePassword: true,
				src: '../../../static/eye-1.png',
				userName:"",
				pwd:"",
				nickName:"",
				rePwd:"",
			}
		},
		onLoad() {
			console.log("init")
		},
		methods: {
			changePassword: function() {
                this.showPassword = !this.showPassword;
            },
			changeRePassword: function() {
			    this.showRePassword = !this.showRePassword;
			},
			register:function(){
				this.$data.notice="";
				if(this.$data.userName.length!=11){
					this.$data.notice="手机号格式不正确";
					return false;
				}
				if(this.$data.pwd.length==0){
					this.$data.notice="密码不可以为空";
					return false;
				}
				if(this.$data.rePwd!=this.$data.pwd){
					this.$data.notice="两次输入的密码不一致";
					return false;
				}
				uni.request({
					url:baseUrl+"/api/user/register",
					method:"POST",
					data:{userName:this.$data.userName,nickName:"",pwd:this.$data.pwd},
					success: (res) => {
						console.log(res.data.code)
						console.log(typeof res.data.code)
						console.log(JSON.stringify(res))
						if(res.data.code==0){
						
							uni.setStorageSync('authInfo', JSON.stringify(res.data.result));
							uni.setStorageSync('token', JSON.stringify(res.data.result.token));
							uni.redirectTo({
								url:"/pages/home/home"
							})
							
						}else{
							this.$data.notice=res.data.message;
						}
					    
					       
					}
				})
				console.log(this.$data.userName)
				console.log(this.$data.pwd);
			},
			login:function(){
				uni.redirectTo({
					url:"/pages/login/login"
				})
			}
		}
	}
</script>

<style scoped>
	.example {
		padding: 15px;
		background-color: #fff;
	}
	
	.segmented-control {
		margin-bottom: 15px;
	}
	
	.button-group {
		margin-top: 15px;
		display: flex;
		justify-content: space-around;
	}
	
	.form-item {
		display: flex;
		align-items: center;
	}
	
	.button {
		display: flex;
		align-items: center;
		height: 35px;
		margin-left: 10px;
	}
	/* .content {
		height:100%;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}
	.text-nitice {
		
		display: flex;
		justify-content: center;
	}
	.nitice {
		font-size:24rpx;
		color: #f00;
	}
	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}

    .nvue-page-root {
        background-color: #F8F8F8;
        padding-bottom: 20px;
    }

    .page-title {
        /* #ifndef APP-NVUE */
        display: flex;
        /* #endif */
        flex-direction: row;
        justify-content: center;
        align-items: center;
        padding: 35rpx;
    }

    .page-title__wrapper {
        padding: 0px 20px;
        border-bottom-color: #D8D8D8;
        border-bottom-width: 1px;
    }

    .page-title__text {
        font-size: 16px;
        height: 48px;
        line-height: 48px;
        color: #BEBEBE;
    }

    .title {
        padding: 5px 13px;
    }

    .uni-form-item__title {
        font-size: 16px;
        line-height: 24px;
    }

    .uni-input-wrapper {
        /* #ifndef APP-NVUE */
        display: flex;
        /* #endif */
        padding: 8px 13px;
        flex-direction: row;
        flex-wrap: nowrap;
        background-color: #FFFFFF;
    }

    .uni-input {
        height: 28px;
        line-height: 28px;
        font-size: 15px;
        padding: 0px;
        flex: 1;
        background-color: #FFFFFF;
    }

    .uni-icon {
        font-family: uniicons;
        font-size: 24px;
        font-weight: normal;
        font-style: normal;
        width: 24px;
        height: 24px;
        line-height: 24px;
        color: #999999;
    }

    .uni-eye-active {
        color: #007AFF;
    }
	
	button {
	    margin-top: 10rpx;
	    margin-bottom: 10rpx;
		margin-left: 35rpx;
		
	}
	
	.button-sp-area {
	    margin: 0 auto;
	    width: 60%;
	} */
</style>
